import User from "../entities/User";
import Operator from "./Operator";
import {RC} from "../config/RC";
import bcryptjs from "bcryptjs"

class CheckPasswordOperator extends Operator{
    public async execute(): Promise<RC> {
        const user_id: string = this.args.getProperty('userId');
        if (user_id === '' || user_id === null || user_id === undefined) {
            return RC.INVALID_ARGUMENT;
        }
        try {
            const user_password:string = this.args.getProperty('password');
            const correct = await User.CheckPassword(user_id,user_password);
            if (!correct) {
                return RC.PASSWORD_INCORRECT;
            } else {
                this.args.setProperty('password_is_correct', correct);
                return RC.SUCCESS;
            }
        } catch (error) {
            // 处理异常情况
            console.error('Error checking passwd:', error);
            return RC.INTERNAL_ERROR;
        }
    }
}

export default CheckPasswordOperator;